Skip to content

Fix acl.resolvePermission not working with wildcard request - #3293

Merged
bajtos merged 1 commit into
strongloop:masterfrom
faridnsh:bugfix/acl-checkpermission
Sep 27, 2017
Merged

bajtos merged 1 commit into
strongloop:masterfrom
faridnsh:bugfix/acl-checkpermission

Conversation

@faridnsh

@faridnsh faridnsh commented Mar 18, 2017 •

Copy link
Copy Markdown
Contributor

Description

When acl.resolvePermission was called with a request containing a wildcard, it would return the matching acl with lowest score instead of higher.

Related issues

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

@slnode

slnode commented Mar 18, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

3 similar comments
@slnode

slnode commented Mar 18, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Mar 18, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Mar 18, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

@ebarault

ebarault commented Mar 19, 2017 •

Copy link
Copy Markdown
Contributor

Thanks @alFReD-NSH for your pull request.
Please as a starting point see my post here

I'll further comment asap, but after some investigations to understand the method you're willing to change was implemented this way, i can at least say that this looks as a breaking change to me, more than a bug.

As i commented in the original issue you should not implement the access-control in lb this way.
More on this latter.

@bajtos
bajtos requested review from raymondfeng and ritch March 20, 2017 10:43
@bajtos

bajtos commented Mar 20, 2017

Copy link
Copy Markdown
Member

When acl.resolvePermission was called with a request containing a wildcard, it would return the matching acl with lowest score instead of higher.

I am afraid this is beyond my current understanding of our ACL system. @raymondfeng @ritch you are the authors of the original design for prioritisation of ACL entries, what's you opinion on this proposal?

@bajtos

bajtos commented Mar 20, 2017

Copy link
Copy Markdown
Member

@slnode ok to test

@ebarault

ebarault commented Mar 20, 2017 •

Copy link
Copy Markdown
Contributor

Given that comment // For wildcard match, find the strongest permission here

The implementation matches the intention and there's no missing break. Question remains: why this behavior? and what was the intention with wildcards in access requests? (@ritch, @raymondfeng)

I cannot find any instance in the code base where an access request does not represent exactly one specific request: targeting one model, one method, one accessType.

I cannot find either any excerpts of former docs where the checkPermission was used directly by developers: shouldn't it be a private method instead as the standard behavior would be to use the built-in access control system?

@raymondfeng

Copy link
Copy Markdown
Member

In this particular case:

var acls = [
      {
        'model': 'account',
        'accessType': '*',
        'permission': 'DENY',
        'principalType': 'ROLE',
        'principalId': '$everyone',
      },
      {
        'model': 'account',
        'accessType': '*',
        'permission': 'ALLOW',
        'principalType': 'ROLE',
        'principalId': '$owner',
      }];

The 2nd rule is stronger than the 1st one as it's more specific about the principal. The score is calculated by (model, property, accessType, principal, permission). The current code seems to assume that all wildcard rules have the same score. As a result, it continues to search for stronger permission.

If two rules cannot produce the same score, adding break probably make sense.

@ebarault

ebarault commented Mar 21, 2017 •

Copy link
Copy Markdown
Contributor

thx @raymondfeng for your time.
the issue actually is not with wildcards in ACLs but with wildcards in AccessRequests.

🖐 AFAIK AccessRequests created by LB's access control system have no wildcards
So an AccessRequest with a wildcard would have been created by the developer for some purpose.

ATM if ACL.checkPermission(principalType, principalId, model, property, accessType) is called with a wildcard on model, property or accessType, then whatever the ACLs' score order, the ACL.resolvePermission() algorithm will resolve with the strongest permission, hence DENY (score 4) if one ACL of the model is DENY.

My main point is actually to argue that it has currently no meaning to call ACL.checkPermission() with any of these wildcards and the current code will resolve unexpected results. So developers should currently not use it with wildcards (as in the original issue behind this PR, see #2153).

If a fix was to be worked out, i wanted to understand what was your idea with the following piece of code:

      if (!req.isWildcard()) {  
        // ...
      } else {
        // ...
        // For wildcard match, find the strongest permission
        var candidateOrder = AccessContext.permissionOrder[candidate.permission];
        var permissionOrder = AccessContext.permissionOrder[permission];
        if (candidateOrder > permissionOrder) {
          permission = candidate.permission;
        }
      }

which is equivalent to write:

if (accessRequest.isWildcard()) {
  // pick the strongest permissions, according to the following ranking:
  /*
  AccessContext.permissionOrder = {
    DEFAULT: 0,
    ALLOW: 1,
    ALARM: 2,
    AUDIT: 3,
    DENY: 4,
  };
*/
}

👉 Other way round: the methods from ACL model should be used only internally.

@faridnsh

faridnsh commented Mar 23, 2017 •

Copy link
Copy Markdown
Contributor Author

I appreciate the comments guys. @raymondfeng basically said in other words why I think this is bug and should be fixed.

@ebarault Basically I use checkPermission to see if user has access to a certain screen and if it could match wildcard requests, it would make coding it simpler. Since there is isWildcard method on the request object, I believe it's appropriate for it be wildcard.

@ebarault

Copy link
Copy Markdown
Contributor

@alFReD-NSH : by screens do you mean MVC views served by the template engine?

@faridnsh

Copy link
Copy Markdown
Contributor Author

@ebarault Technically the check is for the navigation menu. If the user doesn't have access to an item in it, it shouldn't be there.

@ebarault

ebarault commented Mar 23, 2017 •

Copy link
Copy Markdown
Contributor

I see.
Could you check using the ACL.checkAccessForContext() instead of checkPermission (without your fix)? I'd like to test this before going further.

I'm not confident with the current behavior which consist in dealing with any wildcard in an AccessRequest the same way (see AccessRequest.isWildCard())

@faridnsh

Copy link
Copy Markdown
Contributor Author

@ebarault Same thing happens.

@bajtos

bajtos commented Mar 29, 2017

Copy link
Copy Markdown
Member

Ping, what's the status of this pull request? How to move it forward?

@ebarault

ebarault commented Mar 30, 2017 •

Copy link
Copy Markdown
Contributor

@bajtos, @alFReD-NSH : i validate an improvement can be made here, and the overall idea in this PR makes sense to me now (especially now that the issue is confirmed in ACL.checkAccessForContext()).

I'd just would like to take some time to review the whole authorization sequence once more to understand the potential impact of treating any wildcard access request the same way.

@chris08002

Copy link
Copy Markdown

Any news on this one?

@ebarault

Copy link
Copy Markdown
Contributor

IMO the rationale described in this PR is valid. The implementation remains to be reviewed.

@stale stale Bot added the stale label Sep 20, 2017
@stale

stale Bot commented Sep 20, 2017

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@slnode

slnode commented Sep 20, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Sep 20, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

2 similar comments
@slnode

slnode commented Sep 20, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Sep 20, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

@stale stale Bot removed the stale label Sep 20, 2017
@bajtos

bajtos commented Sep 20, 2017

Copy link
Copy Markdown
Member

Hello, I have re-read the discussion above and as I understand it, the changes are going in the right direction and there are no known problems. In that light, I am proposing to move forward and land this pull request as it is now.

Any objections?

@alFReD-NSH would you mind rebasing the patch on top of the latest master?

@bajtos bajtos self-assigned this Sep 20, 2017
@supermafete

Copy link
Copy Markdown

Definitely that 'break' in this PR is necessary in the code, but also is necessary some more stuff. Please, review my PR #3618 relating issue #3518.

When acl.resolvePermission was called with a request containing a
wildcard, it would return the matching acl with lowest score instead of
higher.

Fixes #2153
@slnode

slnode commented Sep 27, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

2 similar comments
@slnode

slnode commented Sep 27, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Sep 27, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

@faridnsh

Copy link
Copy Markdown
Contributor Author

I have rebased this against the latest master.

@bajtos

bajtos commented Sep 27, 2017

Copy link
Copy Markdown
Member

I checked few of the downstream builds, they are failing because nsp check reports vulnerable dependencies. I believe that's not related to this pull request and we can ignore these failures.

@bajtos
bajtos merged commit ef7175a into strongloop:master Sep 27, 2017
@bajtos

bajtos commented Sep 27, 2017

Copy link
Copy Markdown
Member

Landed, thank you @alFReD-NSH for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACL checkpermission not working properly

8 participants